﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LQB;
using MS_UI;

namespace Tap
{
    public partial class UserControl1: UserControl
    {
       
        public UserControl1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);
            Timer mytimer = new Timer();
            mytimer.Interval = 1000;
            mytimer.Tick += Mytimer_Tick;
            mytimer.Enabled = true;
            this.Load += UserControl1_Load;
        }

        private void Mytimer_Tick(object sender, EventArgs e)
        {
            if (this.DeviceStateName != null)
            {
                if (CommonMethod.CurrentValue != null && CommonMethod.CurrentValue.ContainsKey(this.DeviceStateName))
                {
                    ActualValue = CommonMethod.CurrentValue[DeviceStateName] == "1" ? true : false;
                }
            }
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {
            if (actualValue)
            {
                this.MainPic.Image = MS_UI.Properties.Resources.阀门打开;
            }
            else
            {
                this.MainPic.Image = MS_UI.Properties.Resources.阀门关闭;

            }

        }

        private bool actualValue = false;
        public bool ActualValue
        {
            get { return actualValue; } 
            set
            {
                actualValue = value;
                if(actualValue)
                {
                    this.MainPic.Image = MS_UI.Properties.Resources.阀门打开;
                }
                else
                {
                    this.MainPic.Image = MS_UI.Properties.Resources.阀门关闭;

                }


            }
        }
        public delegate void TapClickDelegate(object sender, EventArgs e);


        // 定义设备状态变量
        public string DeviceStateName { get; set; }
        // 定义设备启动变量
        public string DeviceStartName { get; set; }
        // 定义设备停止变量
        public string DeviceStopName { get; set; }
        // 定义设备名称
        public string DeviceName { get; set; }

        public event TapClickDelegate UserControlClick;

        private void MainPic_DoubleClick(object sender, EventArgs e)
        {
            if(UserControlClick!= null)
            {
                UserControlClick(sender,new EventArgs());
            }
        }
    }
}
